<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Project extends Model
{
    use SoftDeletes;
    protected $table='projects';
    protected $guarded=[];
    protected $dates = ['delete_at'];

    //定义项目表和调查表之间的关联
    public function survey()
    {
        return $this->hasMany('App\Models\Survey','project_id','id');
    }

    //保存项目

    public static function newProject($request){
       /* $data['project_number']=$request->project_number;*/
        $data['name']=$request->name;
        $data['levy_scope']=$request->levy_scope;
        /*$data['levy_area']=$request->levy_area;*/
        /*$data['start_end_time']=$request->start_end_time;*/
        $data['actuator']=$request->actuator;
        /*$data['project_leader']=$request->project_leader;*/
        $newProject=Project::create($data);
        if($newProject){
            return redirect()->back()->with('status','小主！新建成功！');
        }else{
            return redirect()->back()->with('status','小主！新建失败!');
        }
    }


    /*
     * 修改项目
     * */
    public static function updateProject($request){
       /* $data['project_number']=$request->project_number;*/
        $data['name']=$request->name;
        $data['levy_scope']=$request->levy_scope;
        /*$data['levy_area']=$request->levy_area;*/
        /*$data['start_end_time']=$request->start_end_time;*/
        $data['actuator']=$request->actuator;
        /*$data['project_leader']=$request->project_leader;*/
        $updateProject=Project::where('id',$request->project_id)->update($data);
        if($updateProject){
            return  back()->with('status','修改成功');
        }else{
            return  back()->with('status','项目信息未做任何修改');
        }
    }
}
